﻿@model ViewPostModel
@using LastoRevival.Service.Contracts.Models;


@{ ViewBag.Title = Model.Subject; }
@{ ViewBag.ActivePostID = Model.PostID; }
@{ ViewBag.ReturnView = "View"; }
@{ var profile = (UserProfile)ViewBag.UserProfile; }

@{
	this.AddIndexBreadCrumb();
	this.AddForumBreadCrumb(Model.ForumID);
	this.AddCurrentBreadCrumb(LanguageLoader.GetWord("ViewingPostBreadCrumbText"));
}

@{
	
	const string quoteFormat = "[quote][i][b]{0}[/b][/i]\r\n{1}[/quote]";
	var quotedText = string.Format(quoteFormat, 
									string.Format(LanguageLoader.GetWord("QuoteAuthorFormat"), Model.UserName),
									Model.BodyUnformatted);
	
}

@Html.ValidationSummary()

<div id="post">

	@Html.Partial("PostDetails")
	
	<div id="post-footer">
		@if (Model.LastEdit.HasValue) 
		{
			<span id="last-edit">@string.Format(LanguageLoader.GetWord("LastEditFormat"), Model.LastEdit, Model.LastEditedBy)</span>
		}
		<span id="signature">@Html.Raw(Model.Signature)</span>
		<span id="user-image"></span>
	</div>
	
	<div class="thread" id="thread-@Model.ThreadID">	
	@Html.Partial("Thread", Model.Thread.TopMessage)
	</div>
</div>


<script type="text/javascript">

	$(function ()
	{
		$("#quote-previous").click(quotePrevious);
		$("#preview").click(previewPost);
	});

	function quotePrevious()
	{
		var quote = $("#quotedText").val()
		$("#bodyField").val($("#bodyField").val() + quote);
	}
	
	function previewPost()
	{
		alert("preview");
	}
	
</script>



@if (Html.IsAuthenticated() && !Model.Locked)
{
	<div id="quick-reply">
	
		@{ 
			var reply = (CreateReplyModel)ViewBag.FailedReply;

			reply = reply == null ? new CreateReplyModel() : reply;
		}

	
		<input type="hidden" id="quotedText" value="@quotedText" />

		<form id="quick-reply-form" action="@Url.Action("Reply", "Post", new { forumID = Model.ForumID })" method="post">
	
			<div class="postform">
				@Html.Hidden("ForumID", Model.ForumID)
				@Html.Hidden("ThreadID", Model.ThreadID)
				@Html.Hidden("ParentPostID", Model.PostID)

				@Html.Partial("PostForm", reply)

				<span id="buttons">
					<button id="post-message" type="submit">@LanguageLoader.GetWord("PostButtonLabel")</button>
					<button id="preview" type="button">@LanguageLoader.GetWord("PreviewButtonLabel")</button>
					<button id="reset" type="reset">@LanguageLoader.GetWord("ResetButtonLabel")</button>
					<button id="quote-previous" type="button">@LanguageLoader.GetWord("QuoteButtonLabel")</button>
				</span>

			</div>
		</form>
						
	</div>
}
